package com.android.memoprendiz.controller;

import com.android.memoprendiz.model.Configuration;
import com.android.memoprendiz.model.ConfigurationsDAO;
import com.android.memoprendiz.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

public class MenuInicialActivity extends Activity/*extends ListActivity */{

	private String[] sentencas;
	private static final int ACTIVITY_CONFIGURACOES = 1;
	
    public void onResume(){
    	super.onResume();
        
        ConfigurationsDAO CD = new ConfigurationsDAO(this);
        Configuration config = CD.getConfiguration();
        int id = this.getResources().getIdentifier(config.getCaminhoEstilo(), "style",this.getPackageName());
        this.setTheme(id);
    }
	
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        ConfigurationsDAO CD = new ConfigurationsDAO(this);

        int id = this.getResources().getIdentifier(CD.getConfiguration().getCaminhoEstilo(), "style",this.getPackageName());
        this.setTheme(id);
        
        
        setContentView(R.layout.activity_menu_inicial);   
        this.sentencas = getResources().getStringArray(R.array.sentencas);

    }
    
	public void eventoBtn(View v){
		switch(v.getId()){
			case R.id.button1:
				startActivity(new Intent(getApplicationContext(), JogarActivity.class));
				break;
			case R.id.button2:
				startActivityForResult(new Intent(getApplicationContext(), ConfiguracaoActivity.class), ACTIVITY_CONFIGURACOES);
				break;
			case R.id.button3:
				startActivity(new Intent(getApplicationContext(), AjudaActivity.class));
				break;
			case R.id.button4:
				startActivity(new Intent(getApplicationContext(), RankingActivity.class));
				break;
			case R.id.button5:
				finish();
				break;
			
		}
	}
	    
    @Override
	protected void onActivityResult(int codigo, int resultado, Intent it){
    	super.onActivityResult(codigo, resultado, it);
    	
        if(codigo == ACTIVITY_CONFIGURACOES){
            Bundle params = it != null ? it.getExtras(): null;
                
               
                String temaDefinido = params.getString("tema");
                String fraseTemaDefinido = "";
                ConfigurationsDAO CD = new ConfigurationsDAO(this);
                Configuration config = CD.getConfiguration();
                Log.w("Configuracoes tema -> ", "."+config.getCaminhoEstilo()+".  ."+ temaDefinido+".");
                
                if(!(CD.getConfiguration().getCaminhoEstilo().equals(temaDefinido))){
                    fraseTemaDefinido = "\n" + this.sentencas[13];
                }else{
                	fraseTemaDefinido = "";
                }
                config = new Configuration(params.getString("tema"), params.getString("nivel")); 
                CD.saveConfiguration(config);
                if(params != null){
                    Toast.makeText(this, this.sentencas[0]+  params.getString("nivel").charAt(1) + 
                  					 "\n"+this.sentencas[1] +" "+params.getString("tema") +
                  					 fraseTemaDefinido, 
                       					 Toast.LENGTH_LONG).show();
                
            }
        }  
    } 
    
    

}